/*//此函数执行会返回一个数组，数组里面包含两个用户信息
function createUserList() {
  return [
    {
      userId: 1,
      avatar: '../../../public/avatar.jpg',
      username: 'xiaomin',
      password: '111111',
      desc: '聊天用户',
      realname: '小明',
      routes: [
        {
          userId: 2,
          username: 'xiaohong',
          realname: '小红',
          avatar: '../../../public/avatar.jpg',
          newestMessage: { initiator: 'xiaomin', message: '喂，小红在干嘛', sendTime: 1233445 }
        },
        {
          userId: 3,
          username: 'xiaogang',
          realname: '小刚',
          avatar: '../../../public/avatar.jpg',
          newestMessage: { initiator: 'xiaomin', message: '喂，小刚在干嘛', sendTime: 1233445 }
        },
        {
          userId: 4,
          username: 'xiaodong',
          realname: '小东',
          avatar: '../../../public/avatar.jpg',
          newestMessage: { initiator: 'xiaomin', message: '喂，小东在干嘛', sendTime: 1233445 }
        },
      ],
      token: 'xiaomin TOKEN',

    },
    {
      userId: 2,
      avatar: '../../../public/avatar.jpg',
      username: 'xiaohong',
      password: '111111',
      desc: '聊天用户',
      realname: '小红',
      routes: [
        {
          userId: 1,
          username: 'xiaomin',
          avatar: '../../../public/avatar.jpg',
          newestMessage: { initiator: 'xiaomin', message: '喂，小红在干嘛', sendTime: 1233445 }
        },
      ],
      token: 'xiaohong TOKEN',
    },
  ]
}

//对外暴露一个数组，数组里面包含两个接口，用于获取用户信息的假接口
export default [
  //用户登录接口
  {
    url: '/api/user/login',  //请求地址
    method: 'post',  //请求方式
    response: ({ body }: any) => {
      //获取请求体携带过来的用户名与密码
      const { username, password } = body
      //调用获取用户信息函数，用于判断是否有此用户
      const checkUser = createUserList().find((item) => item.username === username && item.password === password)
      //没有用户返回失败信息
      if (!checkUser) {
        return { code: 201, data: '账号或密码不正确' }
      }
      //如果有则返回成功信息
      const { token } = checkUser
      return { code: 200, data: token }
    },
  },
  //获取用户信息
  {
    url: '/api/user/info',
    method: 'get',
    response: (request: any) => {
      //获取请求头携带token
      const token = request.headers.token
      //查看用户信息是否包含有此token用户
      const checkUser = createUserList().find((item) => item.token === token)
      if (checkUser) {
        //如果有返回成功信息
        return { code: 200, data: checkUser }
      } else {
        //没有返回失败的信息
        return { code: 201, data: '获取用户信息失败' }
      }
    }
  },
  //用户退出登录
  {
    url: '/api/user/logout',
    method: 'post',
    response: ({ body }: any) => {
      // 返回成功状态
      return { code: 200, data: '退出登录成功' }
    },
  }
]
*/
